import org.apache.hadoop.conf.Configuration;
import org.apache.hadoop.fs.FSDataInputStream;
import org.apache.hadoop.fs.FileSystem;
import org.apache.hadoop.fs.Path;
import org.apache.hadoop.io.IOUtils;

import java.net.URI;

public class DemoTwo {

    public static void main(String[] args) {
        //案例2：读取hdfs数据

        try {

            System.setProperty("hadoop.home.dir", "D:\\code2\\hadoop-2.7.3");
            System.setProperty("HADOOP_USER_NAME", "root");

            String reaUrl = "hdfs://192.168.75.11:9000/test/17.txt";
            Configuration conf = new Configuration();
            FileSystem fileSystem = FileSystem.get(URI.create(reaUrl), conf);

            FSDataInputStream fsDataInputStream = fileSystem.open(new Path(reaUrl));
            IOUtils.copyBytes(fsDataInputStream, System.out, 4096, false);

        } catch (Exception e) {
            e.printStackTrace();
        }
    }
}